home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / TUTORC.ZIP / TUT7.C < prev    next >
C/C++ Source or Header  |  1994-10-30  |  19KB  |  468 lines

  1. /*
  2.   tut7.c
  3.   10/30/94
  4.   from tutprog7.pas
  5.   Adapted from Denthor's tutprog7.pas
  6.   Translated into C, from Denthor's VGA Trainer, by
  7.   Steve Pinault, scp@ohm.att.com
  8.   Compiled with Microsoft Visual C++ 1.5 (Microsoft C 8.0)
  9.   To compile:
  10.   First compile the subroutines in tutsubs.c with the batch file 
  11.   cltutsub.bat
  12.   Then compile any of the tutor programs with the batch file
  13.   cltut.bat
  14.   Example: C:>cltutsub
  15.            C:>cltut tut7.c
  16.            to compile this program.
  17. */
  18.  
  19. #include "tutheadr.h"
  20.  
  21. struct toastinfo
  22. {
  23.   int x;
  24.   int y;
  25.   int speed;
  26.   int frame;
  27.   int active;
  28. } toaster[10];
  29.  
  30. char ourpal[256][3];
  31.  
  32. char frame1[30*48]={
  33. 0,0,0,0,5,5,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,5,5,5,5,5,5,
  34. 7,7,7,7,0,0,0,0,0,0,0,5,5,5,5,5,5,5,5,5,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,
  35. 5,7,7,7,7,7,7,7,8,8,7,7,7,7,7,7,0,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0,0,0,0,0,0,0,0,
  36. 0,0,0,0,0,5,5,7,7,7,7,7,8,8,7,8,8,7,8,7,8,7,7,7,5,8,8,8,8,5,5,5,5,5,5,5,5,5,5,5,
  37. 5,0,0,0,0,0,0,0,0,0,0,0,5,7,7,7,7,7,7,8,7,7,7,8,7,7,7,7,7,7,0,0,0,0,0,0,8,5,5,5,
  38. 5,5,5,5,5,5,5,5,5,0,0,0,0,0,0,0,0,0,0,5,7,7,8,8,7,7,8,7,7,8,7,7,7,7,7,0,0,0,0,0,
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,0,
  139. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  140. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  141. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  142. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  143. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  144. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  145. };
  146.  
  147.  
  148. // DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD}
  149. // Procedure putico(X,Y:Word;VAR sprt : icon;Where:Word); ASSEMBLER;
  150. //   { This puts an icon, EXCEPT it's color 0 (black) pixels, onto the screen
  151. //     "where", at position X,Y }
  152. // label
  153. //   _Redraw, _DrawLoop, _Exit, _LineLoop, _NextLine, _Store, _NoPaint;
  154. void putico(int X, int Y, char far* Sprt, int where)
  155. {
  156.   _asm
  157.   {
  158.     push  ds
  159.     push  es
  160.     lds   si,Sprt
  161.     mov   ax,X    ; { ax = x }
  162.     mov   bx,Y    ; { bx = y }
  163. ; _Redraw:
  164.     push    ax
  165.     mov     ax,where
  166.     mov     es,ax
  167.  
  168.     mov     ax, bx   ;               {; ax = bx  x = y}
  169.     mov     bh, bl   ;               {; y = y * 256  bx = bx * 256}
  170.     xor     bl, bl
  171.     shl     ax, 1
  172.     shl     ax, 1
  173.     shl     ax, 1
  174.     shl     ax, 1
  175.     shl     ax, 1
  176.     shl     ax, 1    ;     {; y = y * 64   ax = ax * 64}
  177.     add     bx, ax   ;     {; y = (y*256) + (Y*64)  bx = bx + ax (ie y*320)}
  178.  
  179.     pop     ax       ;               {; get back our x}
  180.  
  181.  
  182.     add     ax, bx   ;               {; finalise location}
  183.     mov     di, ax
  184.  
  185.     mov   dl,30    ;{ dl = height of sprite }
  186.     xor   ch,ch
  187.     mov   cl,48    ; { cx = width of sprite }
  188.     cld
  189.     push  ax
  190.     mov   ax,cx
  191. _DrawLoop:
  192.     push  di       ;     { store y adr. for later }
  193.     mov   cx,ax    ;      { store width }
  194. _LineLoop:
  195.     mov   bl,byte ptr [si]
  196.     or    bl,bl
  197.     jnz   _Store
  198. ; _NoPaint:
  199.     inc    si
  200.     inc    di
  201.     loop   _LineLoop
  202.     jmp    _NextLine
  203. _Store:
  204.     movsb
  205.     loop  _LineLoop
  206. _NextLine:
  207.     pop   di
  208.     dec   dl
  209.     jz    _Exit
  210.     add   di,320   ;     { di = next line of sprite }
  211.     jmp   _DrawLoop
  212. _Exit:
  213.     pop   ax
  214.     pop   es
  215.     pop   ds
  216.   }
  217. }
  218.  
  219. // {DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD}
  220. // Procedure SetUpScreen;
  221. //   { This procedure sets up the static background to be used in the program }
  222. void SetUpScreen()
  223. {
  224.   char circ[5][5]=
  225.          {{0,10,10,10,0},
  226.          {10,13,12,11,10},
  227.          {10,12,12,11,10},
  228.          {10,11,11,11,10},
  229.           {0,10,10,10,0}};
  230.   int x,y,loop1,loop2,loop3;
  231.   Pal (1,22,22,22);
  232.   Pal (2,45,45,45);
  233.   Pal (3,59,59,59);
  234.   Pal (4,63,63,27);
  235.   Pal (5,39,63,3);
  236.   Pal (6,51,39,3);
  237.   Pal (7,3,27,3);
  238.   Pal (8,15,39,15);
  239.   Pal (9,35,35,35);
  240.   Pal (10, 0, 0,40);
  241.   Pal (11,10,10,50);
  242.   Pal (12,20,20,60);
  243.   Pal (13,30,30,63);
  244.  
  245.   for(loop1=50;loop1<101;loop1++)
  246.     Pal ((char)loop1,(char)0,(char)0,(char)(loop1-36));
  247.  
  248.   for(loop1=0;loop1<256;loop1++)
  249.      GetPal ((char)loop1,&ourpal[loop1][1],&ourpal[loop1][2],&ourpal[loop1][3]);
  250.  
  251.   for(loop1=0;loop1<320;loop1++)
  252.   {
  253.     Funny_Line (0,199,loop1,0,Vaddr);
  254.   }
  255.   for(loop1=0;loop1<200;loop1++)
  256.   {
  257.     Funny_Line (0,199,319,loop1,Vaddr);
  258.   }
  259.  
  260.   for(loop1=0;loop1<200;loop1++)
  261.   {
  262.     x=random(315);
  263.     y=random(195);
  264.     for(loop2=0;loop2<5;loop2++)
  265.       for(loop3=0;loop3<5;loop3++)
  266.         if(circ[loop2][loop3]!=0) 
  267.           PutPixel (x+loop2,y+loop3,circ [loop2][loop3],Vaddr);
  268.   }
  269.   Flip2(Vaddr,VGA);  //{ Copy the entire screen at vaddr, our virtual screen }
  270.                      //{ on which we have done all our graphics, onto the    }
  271.                      //{ screen you see, VGA }
  272.   Flip2(Vaddr,Vaddr2);
  273. }
  274.  
  275.  
  276. // {DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD}
  277. // Procedure ScreenTrans (x,y:word);
  278. //   { This is a small procedure to copy a 30x30 pixel block from coordinates
  279. //     x,y on the virtual screen to coordinates x,y on the true vga screen }
  280. void ScreenTrans(int x, int y)
  281. {
  282.   _asm 
  283.   {
  284.     push    ds
  285.     push    es
  286.     mov     ax,Vaddr
  287.     mov     es,ax
  288.     mov     ax,Vaddr2
  289.     mov     ds,ax
  290.     mov     bx,x
  291.     mov     dx,y
  292.     push    bx        ;             {; and this again for later}
  293.     mov     bx, dx    ;             {; bx = dx}
  294.     mov     dh, dl    ;             {; dx = dx * 256}
  295.     xor     dl, dl
  296.     shl     bx, 1
  297.     shl     bx, 1
  298.     shl     bx, 1
  299.     shl     bx, 1
  300.     shl     bx, 1
  301.     shl     bx, 1     ;             {; bx = bx * 64}
  302.     add     dx, bx    ;             {; dx = dx + bx (ie y*320)}
  303.     pop     bx        ;             {; get back our x}
  304.     add     bx, dx    ;             {; finalise location}
  305.     mov     di, bx    ;             {; es:di = where to go}
  306.     mov     si, di
  307.     mov     al,60
  308.     mov     bx, 30    ;    { Height of block to copy }
  309. move1:
  310.     mov     cx, 24    ;    { Width of block to copy divided by 2 }
  311.     rep     movsw
  312.     add     di,110h   ;    { 320 - 48 = 272 .. or 110 in hex }
  313.     add     si,110h
  314.     dec     bx
  315.     jnz     move1
  316.  
  317.     pop     es
  318.     pop     ds
  319.   }
  320.   // { I wrote this procedure late last night, so it may not be in it's
  321.   //   most optimised state. Sorry :-)}
  322. }
  323.  
  324.  
  325. // {DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD}
  326. // Procedure NewToaster;
  327. //   { This adds a new toaster to the screen }
  328. void NewToaster() 
  329. {
  330.   int loop1;
  331.   for(loop1=0;loop1<10;loop1++)
  332.   {
  333.     if (!(toaster[loop1].active))
  334.     {
  335.       toaster[loop1].x=random (200)+70;
  336.       toaster[loop1].y=0;
  337.       toaster[loop1].active=1;
  338.       toaster[loop1].frame=1;
  339.       toaster[loop1].speed=random (3)+1;
  340.       break;
  341.     }
  342.   }
  343. }
  344.  
  345. // {DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD}
  346. // Procedure Fly;
  347. //   { This is the procedure where we move and put the toasters }
  348. void Fly()
  349. {
  350.   int loop1;
  351.   int ch;
  352.   for(loop1=0;loop1<10;loop1++)
  353.     toaster[loop1].active=0;
  354.   ch=0x0;
  355.   NewToaster();
  356.   while(ch!=0x1b)  // escape
  357.   {
  358.     if(_bios_keybrd(_KEYBRD_READY))
  359.     {
  360.       ch=(getch()&0x00ff);
  361.       if(ch==0x71)break; // 'q'
  362.       if(ch==0x51)break; // 'Q'
  363.       if(ch==0x1b)break; // ESC
  364.       if(ch==0x20)NewToaster();  //  { If ' ' is pressed, add a toaster }
  365.       if(ch==0x2b)NewToaster();  //  { If '+' is pressed, add a toaster }
  366.       if(ch==0x2d)               //  { if '-' is pressed, remove a toaster }
  367.       {
  368.         for(loop1=0;loop1<10;loop1++)
  369.         {
  370.           if(toaster[loop1].active)
  371.           {
  372.             ScreenTrans (toaster[loop1].x,toaster[loop1].y);
  373.             toaster[loop1].active=0;
  374.             break;
  375.           }
  376.         }
  377.       }
  378.     }
  379.     for(loop1=0;loop1<10;loop1++)
  380.     {
  381.       if(toaster[loop1].active)
  382.       {
  383.         ScreenTrans (toaster[loop1].x,toaster[loop1].y);
  384.           // { Restore the backgrond the toaster was over }
  385.         toaster[loop1].x-=toaster[loop1].speed;
  386.         toaster[loop1].y+=toaster[loop1].speed;
  387.          //  { Move the toaster }
  388.         if((toaster[loop1].x<1)||(toaster[loop1].y>170)) 
  389.         {
  390.           toaster[loop1].active=0;
  391.           NewToaster();
  392.         }
  393.       }
  394.         //{ When toaster reaches the edge of the screen, render it inactive
  395.         //  and bring a new one into existance. }
  396.     }
  397.     for(loop1=0;loop1<10;loop1++)
  398.     {
  399.       if(toaster[loop1].active)
  400.       {
  401.         switch(toaster[loop1].frame)
  402.         {
  403.            case 1: 
  404.              putico (toaster[loop1].x,toaster[loop1].y,frame1,Vaddr);
  405.              break;
  406.            case 3: 
  407.              putico (toaster[loop1].x,toaster[loop1].y,frame2,Vaddr);
  408.              break;
  409.            case 2: 
  410.            case 4: 
  411.              putico (toaster[loop1].x,toaster[loop1].y,frame3,Vaddr);
  412.         }
  413.       }
  414.       toaster[loop1].frame++;
  415.       if(toaster [loop1].frame==5) toaster[loop1].frame=1;
  416.       //  { Draw all the toasters on the VGA screen }
  417.     }
  418.     WaitRetrace();
  419.     Flip2(Vaddr,VGA);
  420.     rotatepal(ourpal,(int)50,(int)100);
  421.   } // end while ch!=ESC
  422. }
  423.  
  424.  
  425. void main()
  426. {
  427.   VirtPtr=&Virtual[0];
  428.   Vaddr = FP_SEG(VirtPtr);
  429.   VirtPtr=&Virtual2[0];
  430.   Vaddr2 = FP_SEG(VirtPtr);
  431.   randomize;     //  { Make sure that the RANDOM funcion really is random }
  432.   _clearscreen(_GCLEARSCREEN);
  433.   printf(  "Hello! This program will demonstrate the principals of animation.\n");
  434.   printf(  "The program will firstly generate an arb background screen to a\n");
  435.   printf(  "virtual page, then flip it to the VGA. A toaster will then start\n");
  436.   printf(  "to move across the screen. Note that the background will be restored\n");
  437.   printf(  "after the toaster has passed over it. You may add or remove toasters\n");
  438.   printf(  "by hitting + or - respectively. Note that the more frames you\n");
  439.   printf(  "use, usually the better the routine looks. Because of space\n");
  440.   printf(  "restrictions, we only had room for three frames.\n");
  441.   printf(  "\n");
  442.   printf(  "The toasters were drawn by Fubar (Pieter Buys) in Autodesk Animator.\n");
  443.   printf(  "I wrote a small little program to convert them into CONSTANTS. See\n");
  444.   printf(  "the main text to find out how to load up AA CEL files directly.\n");
  445.   printf(  "\n");
  446.   printf(  "\n");
  447.   printf(  "Hit any key to contine ...");
  448.   getch();
  449.   SetMCGA();
  450.   SetUpScreen(); //    { Draw the background screen to VADDR, then flip it to
  451.                  //      the VGA screen }
  452.   Fly();         //    { Make the toasters fly around the screen }
  453.   SetText();
  454.   printf(  "All done. This concludes the seventh sample program in the ASPHYXIA\n");
  455.   printf(  "Training series. You may reach DENTHOR under the names of GRANT\n");
  456.   printf(  "SMITH/DENTHOR/ASPHYXIA on the ASPHYXIA BBS. I am also an avid\n");
  457.   printf(  "Connectix BBS user, which is unfortunatly offline for the moment.\n");
  458.   printf(  "For discussion purposes, I am also the moderator of the Programming\n");
  459.   printf(  "newsgroup on the For Your Eyes Only BBS.\n");
  460.   printf(  "The numbers are available in the main text. You may also write to me at:\n");
  461.   printf(  "             Grant Smith\n");
  462.   printf(  "             P.O. Box 270\n");
  463.   printf(  "             Kloof\n");
  464.   printf(  "             3640\n");
  465.   printf(  "I hope to hear from you soon!\n");
  466.   printf("\n\n Translated into Microsoft C by Steve Pinault, \n  scp@ohm.att.com\n\n");
  467. }
  468.